package com.softeem.thymeleafdemo.controller;

import com.softeem.thymeleafdemo.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author mrchai 2020/10/13 16:25
 */
@Slf4j
@Controller
public class UserController {

    @RequestMapping(value = "user/hello",method= RequestMethod.GET)
    public ModelAndView hello(){
        ModelAndView mav = new ModelAndView();
        mav.setViewName("index");
        mav.addObject("msg","这是第一个Thymeleaf测试案例");
        return mav;
    }

    @RequestMapping(value="user/list",method=RequestMethod.GET)
    public ModelAndView list(){

        List<User> list = Arrays.asList(
                new User(1001,"softeem","HKJHKJDHSDKFHSIFHDIUIU",1),
                new User(1002,"admin","HKJHKJDHSDKFHSIFHDIUIU",1),
                new User(1003,"jackson","SDFSDFSDSDFSSFD",0),
                new User(1004,"james","HKJHKJDHSDKFHSIFHDIUIU",0),
                new User(1005,"kobe","SDFSDFSDSDFSSFD",-1),
                new User(1006,"盖伦","HKJHKJDHSDKFHSIFHDIUIU",-1),
                new User(1007,"艾希","SDFSDFSDSDFSSFD",0),
                new User(1008,"瑞兹","HKJHKJDHSDKFHSIFHDIUIU",1)
        );
        log.info(list.toString());
        ModelAndView mav = new ModelAndView();
        mav.setViewName("user/list");
        mav.addObject("list",list);
        return mav;
    }

    @ResponseBody
    @GetMapping("user/list2")
    public List<User> showUsers(){
        return Arrays.asList(
                new User(1001,"softeem","HKJHKJDHSDKFHSIFHDIUIU",1),
                new User(1002,"admin","HKJHKJDHSDKFHSIFHDIUIU",1),
                new User(1003,"jackson","SDFSDFSDSDFSSFD",0),
                new User(1004,"james","HKJHKJDHSDKFHSIFHDIUIU",0),
                new User(1005,"kobe","SDFSDFSDSDFSSFD",-1),
                new User(1006,"盖伦","HKJHKJDHSDKFHSIFHDIUIU",-1),
                new User(1007,"艾希","SDFSDFSDSDFSSFD",0),
                new User(1008,"瑞兹","HKJHKJDHSDKFHSIFHDIUIU",1)
        );
    }
}
